package com.adams.app.model;

import java.util.ArrayList;
import java.util.HashMap;

import android.database.Cursor;

import com.adams.app.dao.SpecialtyDateHelper;
import com.google.gson.Gson;

public class Specialty extends BaseType {
	private static final HashMap<Integer, Specialty> CACHE = new HashMap<Integer, Specialty>();

	public Integer getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getPicture() {
		return picture;
	}

	public String getIntro() {
		return intro;
	}

	public Integer getType() {
		return type;
	}

	private Integer id;
	private String name;
	private String picture;
	private String intro;
	private Integer type;

	private static void addToCache(Specialty specialty) {
		CACHE.put(specialty.getId(), specialty);
	}

	private static Specialty getFromCache(long id) {
		return CACHE.get(id);
	}

	public static Specialty fromJson(String json) {
		return new Gson().fromJson(json, Specialty.class);
	}

	public static Specialty fromCursor(Cursor cursor) {
		long id = cursor.getLong(cursor
				.getColumnIndex(SpecialtyDateHelper.SpecialtyDBInfo._ID));
		Specialty specialty = getFromCache(id);
		if (specialty != null) {
			return specialty;
		}
		specialty = new Gson().fromJson(cursor.getString(cursor
				.getColumnIndex(SpecialtyDateHelper.SpecialtyDBInfo.JSON)),
				Specialty.class);
		addToCache(specialty);
		return specialty;
	}

	public static class SpecialtyRequestData {

		private ArrayList<Specialty> featureJson;

		public ArrayList<Specialty> getSpecialty() {
			return featureJson;
		}
	}
}
